import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/a.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

/// 默认info底部弹出框
showDefaultInfoBottomSheet(
  BuildContext context, {
  Widget child,
  bool isScrollControlled = false,
  bool isDismissible = true,
  bool hasClose = true,
}) =>
    showModalBottomSheet(
        context: context,
        isScrollControlled: isScrollControlled,
        isDismissible: isDismissible,
        backgroundColor: Colors.transparent,
        builder: (BuildContext context) => InfoBottomSheet(
              child: child,
              hasClose: hasClose,
            ));

class InfoBottomSheet extends StatelessWidget {
  final Widget child;
  final bool hasClose;

  const InfoBottomSheet({Key key, this.child, this.hasClose = true})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Container(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(getDp(30)),
              topRight: Radius.circular(getDp(30)),
            )),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Stack(
              clipBehavior: Clip.none,
              children: [
                Positioned(
                    left: 0.0,
                    right: 0.0,
                    top: -getDp(30),
                    child: Image.asset(
                      A.assetsImagesStyleInfo,
                      width: getDp(60),
                      height: getDp(60),
                    )),
                Align(
                  alignment: Alignment.centerRight,
                  child: hasClose
                      ? PressedOpacityButton(
                          padding: EdgeInsets.symmetric(
                            horizontal: getDp(34),
                            vertical: getDp(20),
                          ),
                          onPressed: () => Navigator.of(context).pop(),
                          child: SvgPicture.asset(
                            A.assetsImagesStyleClose,
                            width: getDp(18),
                            height: getDp(18),
                            fit: BoxFit.contain,
                          ),
                        )
                      : SizedBox(
                          height: 50,
                        ),
                )
              ],
            ),
            if (child != null) child,
            SizedBox(
              height: MediaQuery.of(context).padding.bottom +
                  MediaQuery.of(context).viewInsets.bottom +
                  getDp(52),
            )
          ],
        ),
      ),
    );
  }
}
